]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
remoteMenu: Allow separator items to have labels
authorJasper St. Pierre <jstpierre@mecheye.net>
Wed, 24 Apr 2013 20:21:57 +0000 (16:21 -0400)
committerJasper St. Pierre <jstpierre@mecheye.net>
Mon, 13 May 2013 22:34:26 +0000 (18:34 -0400)
This fixes a regression with remote menus where sections have
labels, like gnome-documents.

https://bugzilla.gnome.org/show_bug.cgi?id=700257

js/ui/popupMenu.js
js/ui/remoteMenu.js

index 8a2b06e1af18e9fdc25041ffae86bf517934f640..bfb950ff922bb1ba7d2e81a0be767a7ddb799712 100644 (file)
@@ -393,12 +393,19 @@ const PopupSeparatorMenuItem = new Lang.Class({
     Name: 'PopupSeparatorMenuItem',
     Extends: PopupBaseMenuItem,
 
-    _init: function () {
+    _init: function (text) {
         this.parent({ reactive: false,
                       can_focus: false});
 
+        this._box = new St.BoxLayout();
+        this.addActor(this._box, { span: -1, expand: true });
+
+        this.label = new St.Label({ text: text || '' });
+        this._box.add(this.label);
+        this.actor.label_actor = this.label;
+
         this._separator = new Separator.HorizontalSeparator({ style_class: 'popup-separator-menu-item' });
-        this.addActor(this._separator.actor, { span: -1, expand: true });
+        this._box.add(this._separator.actor, { expand: true });
     }
 });
 
@@ -983,6 +990,9 @@ const PopupMenuBase = new Lang.Class({
     },
 
     _updateSeparatorVisibility: function(menuItem) {
+        if (menuItem.label.text)
+            return;
+
         let children = this.box.get_children();
 
         let index = children.indexOf(menuItem.actor);
index d03ed63b615857239c99c97a91c3bd34d7b227da..758d79ae7b0df813978288d6d9648ec849ffc542 100644 (file)
@@ -11,6 +11,33 @@ const St = imports.gi.St;
 
 const PopupMenu = imports.ui.popupMenu;
 
+function stripMnemonics(label) {
+    if (!label)
+        return '';
+
+    // remove all underscores that are not followed by another underscore
+    return label.replace(/_([^_])/, '$1');
+}
+
+const RemoteMenuSeparatorItemMapper = new Lang.Class({
+    Name: 'RemoteMenuSeparatorItemMapper',
+
+    _init: function(trackerItem) {
+        this._trackerItem = trackerItem;
+        this.menuItem = new PopupMenu.PopupSeparatorMenuItem();
+        this._trackerItem.connect('notify::label', Lang.bind(this, this._updateLabel));
+        this._updateLabel();
+
+        this.menuItem.connect('destroy', function() {
+            trackerItem.run_dispose();
+        });
+    },
+
+    _updateLabel: function() {
+        this.menuItem.label.text = stripMnemonics(this._trackerItem.label);
+    },
+});
+
 const RemoteMenuItemMapper = new Lang.Class({
     Name: 'RemoteMenuItemMapper',
 
@@ -43,10 +70,7 @@ const RemoteMenuItemMapper = new Lang.Class({
     },
 
     _updateLabel: function() {
-        let label = this._trackerItem.label;
-        // remove all underscores that are not followed by another underscore
-        label = label.replace(/_([^_])/, '$1');
-        this._label.text = label;
+        this._label.text = stripMnemonics(this._trackerItem.label);
     },
 
     _updateSensitivity: function() {
@@ -103,7 +127,8 @@ const RemoteMenu = new Lang.Class({
         let item;
 
         if (trackerItem.get_is_separator()) {
-            item = new PopupMenu.PopupSeparatorMenuItem();
+            let mapper = new RemoteMenuSeparatorItemMapper(trackerItem);
+            item = mapper.menuItem;
         } else {
             let mapper = new RemoteMenuItemMapper(trackerItem);
             item = mapper.menuItem;